from django.conf.urls.defaults import *
from models import Post, Forum, Topic

forum_list = Forum.objects.all()
total_topics = 0
total_posts = 0
for forum in forum_list:
	total_topics += forum.topic_set.count()
	total_posts += forum.post_count

forum_args = {'queryset': forum_list, 'template_name': 'beastly/forums.html', 'template_object_name': 'forum', 'allow_empty': True, 'extra_context': {'total_topics': total_topics, 'total_posts': total_posts,},}

posts_list = Post.objects.all()
posts_args = {'queryset': posts_list, 'template_name': 'beastly/posts_list.html', 'template_object_name': 'posts', 'allow_empty': True, 'paginate_by': 20,}

urlpatterns = patterns('beastly.views',
	(r'^new/$', 'new_forum', {}),
	(r'^forums/(?P<forum_id>\d+)/topics/(?P<topic_id>\d+)/$', 'post_list'),
	(r'^forums/(?P<forum_id>\d+)/topics/new/$', 'new_topic', {}),
	(r'^forums/(?P<forum_id>\d+)/$', 'topic_list'),
    (r'^search/$', 'search'),
	(r'^users/(?P<username>[a-zA-Z0-9]+)/$', 'user_profile'),
	(r'^users/$', 'users'),
	(r'^settings/$', 'user_settings'),
	(r'^accounts/profile/$', 'accounts_profile'),
	)

urlpatterns += patterns('',
        (r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'beastly/accounts/login.html'}),
        (r'^logout/$', 'django.contrib.auth.views.logout', {'template_name': 'beastly/accounts/logout.html'}),
)

urlpatterns += patterns('django.views.generic.list_detail',
	(r'^$', 'object_list', forum_args),
	(r'^posts/$', 'object_list', posts_args),
)	
